import { Injectable } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes } from '@angular/router';
import { UserRouteAccessService } from 'app/core';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
import { ElecBicycleAdmin } from 'app/shared/model/elec-bicycle-admin.model';
import { ElecBicycleAdminService } from './elec-bicycle-admin.service';
import { ElecBicycleAdminComponent } from './elec-bicycle-admin.component';
import { ElecBicycleAdminDetailComponent } from './elec-bicycle-admin-detail.component';
import { ElecBicycleAdminUpdateComponent } from './elec-bicycle-admin-update.component';
import { ElecBicycleAdminDeletePopupComponent } from './elec-bicycle-admin-delete-dialog.component';
import { IElecBicycleAdmin } from 'app/shared/model/elec-bicycle-admin.model';

@Injectable({ providedIn: 'root' })
export class ElecBicycleAdminResolve implements Resolve<IElecBicycleAdmin> {
    constructor(private service: ElecBicycleAdminService) {}

    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        const id = route.params['id'] ? route.params['id'] : null;
        if (id) {
            return this.service.find(id).pipe(map((elecBicycleAdmin: HttpResponse<ElecBicycleAdmin>) => elecBicycleAdmin.body));
        }
        return of(new ElecBicycleAdmin());
    }
}

export const elecBicycleAdminRoute: Routes = [
    {
        path: 'elec-bicycle-admin',
        component: ElecBicycleAdminComponent,
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleAdmin.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'elec-bicycle-admin/:id/view',
        component: ElecBicycleAdminDetailComponent,
        resolve: {
            elecBicycleAdmin: ElecBicycleAdminResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleAdmin.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'elec-bicycle-admin/new',
        component: ElecBicycleAdminUpdateComponent,
        resolve: {
            elecBicycleAdmin: ElecBicycleAdminResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleAdmin.home.title'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'elec-bicycle-admin/:id/edit',
        component: ElecBicycleAdminUpdateComponent,
        resolve: {
            elecBicycleAdmin: ElecBicycleAdminResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleAdmin.home.title'
        },
        canActivate: [UserRouteAccessService]
    }
];

export const elecBicycleAdminPopupRoute: Routes = [
    {
        path: 'elec-bicycle-admin/:id/delete',
        component: ElecBicycleAdminDeletePopupComponent,
        resolve: {
            elecBicycleAdmin: ElecBicycleAdminResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'sharedelectricbicycleApp.elecBicycleAdmin.home.title'
        },
        canActivate: [UserRouteAccessService],
        outlet: 'popup'
    }
];
